package com.buanalintas.sandals.pos.shop;

import com.buanalintas.bynga.Dictionary;
import com.buanalintas.bynga.Field;
import com.buanalintas.bynga.Page;
import com.buanalintas.sandals.pos.entities.PosMasterShop;

public class Shop extends Page {

    private Field shopId;
    private Field shopUnitId;
    private Field shopType;
    private Field shopCode;
    private Field shopName;
    private Field shopAddress;
    private Field shopPhone;
    private Field shopContact;

    public Shop() {
        setTheClass(PosMasterShop.class);

        shopId = new Field();
        shopId.setName("shopId");
        shopId.setCaption("id");
        shopId.setListProperties(" align=\"right\" width=\"5%\" nowrap");
        shopId.setInputProperties(" size=\"10\"");
        getFields().add(shopId);

        shopCode = new Field();
        shopCode.setName("shopCode");
        shopCode.setCaption("code");
        shopCode.setListProperties(" align=\"center\" width=\"8%\" nowrap");
        shopCode.setInputProperties(" size=\"14\"");
        shopCode.setRequired(true);
        shopCode.setInputCase(Field.CASE_UPPER);
        getFields().add(shopCode);

        shopName = new Field();
        shopName.setName("shopName");
        shopName.setCaption("name");
        shopName.setListProperties(" align=\"left\" width=\"20%\" nowrap");
        shopName.setInputProperties(" size=\"30\"");
        shopName.setRequired(true);
        shopName.setInputCase(Field.CASE_UPPER);
        getFields().add(shopName);

        shopAddress = new Field();
        shopAddress.setName("shopAddress");
        shopAddress.setCaption("address");
        shopAddress.setListProperties(" align=\"left\" width=\"25%\" nowrap");
        shopAddress.setInputProperties(" rows=\"3\"cols=\"30\"");
        shopAddress.setInputType(Field.INPUT_TEXT_AREA);
        shopAddress.setRequired(true);
        shopAddress.setInputCase(Field.CASE_UPPER);
        getFields().add(shopAddress);

        shopPhone = new Field();
        shopPhone.setName("shopPhone");
        shopPhone.setCaption("Phone");
        shopPhone.setListProperties(" align=\"center\" width=\"14%\" nowrap");
        shopPhone.setInputProperties("size=\"16\"");
        shopPhone.setRequired(true);
        getFields().add(shopPhone);

        shopContact = new Field();
        shopContact.setName("shopContact");
        shopContact.setCaption("Contact");
        shopContact.setListProperties(" align=\"left\" width=\"14%\" nowrap");
        shopContact.setInputProperties("size=\"16\"");
        shopContact.setRequired(true);
        shopContact.setInputCase(Field.CASE_UPPER);
        getFields().add(shopContact);

        shopType = new Field();
        shopType.setName("shopType");
        shopType.setCaption("type");
        shopType.setListProperties(" align=\"center\" width=\"8%\" nowrap");
        shopType.setRequired(true);
        shopType.setInputType(Field.INPUT_COMBO_BOX);
        shopType.setInputProperties(" width=\"30px\" ");
        shopType.getOptions().add(new String[]{"1", "Shop"});
        shopType.getOptions().add(new String[]{"2", "Franchise"});
        getFields().add(shopType);

        shopUnitId = new Field();
        shopUnitId.setName("shopUnitId");
        shopUnitId.setCaption("Unit");
        shopUnitId.setListProperties(" align=\"left\" width=\"5%\" nowrap");
        shopUnitId.setInputProperties(" size=\"30\"");
        shopUnitId.setRequired(true);
        getFields().add(shopUnitId);
        
        fillFields();
        
        getFieldsUnique().add(new Field[]{shopCode});
        getFieldsAdd().remove(shopId);
        getFieldsEdit().remove(shopId);
        getFieldsList().remove(shopId);

        setExportList(getClass().getResourceAsStream("ShopList.jasper"));
        setExport(getClass().getResourceAsStream("Shop.jasper"));
        getController().setOrder(shopName);
    }

    @Override
    public void beforeExport() {
        getExportParams().put("title", Dictionary.getValue(this, "ShopName"));
    }

    @Override
    public void beforeExportMulti() {
        beforeExport();
    }
}
